package clinicapoo.services;

import clinicapoo.dao.Transaction;
import clinicapoo.exceptions.ApplicationException;
import clinicapoo.exceptions.ValidationException;
import clinicapoo.factory.Business;
import clinicapoo.factory.DAO;
import clinicapoo.model.Medico;
import java.util.Collection;
import java.util.List;

/**
 *
 * @author fmontezuma
 */
public class MedicoServices extends BaseServices
{
	public void cadastrar(Medico m) throws ApplicationException
	{
		log.debug(m.toString());

		Transaction tx = null;
		try
		{
			tx = new Transaction();
			Business.medico.cadastrar(m);
			tx.commit();
			log.info("Cliente cadastrado com sucesso: {}", m.toString());
		}
		catch (ApplicationException e)
		{
			if (e instanceof ValidationException)
				log.warn(e.getMessage());
			else
				log.error(e.getMessage());
			tx.rollback();
			throw e;
		}
		catch (Exception e)
		{
			log.error(e.getMessage(), e);
			tx.rollback();
			throw new ApplicationException("Ocorreu um erro inesperado no cadastro médico.", e);
		}
	}

	public List<Medico> listar()
	{
		log.debug("Listando médicos");
		return DAO.medico.listar();
	}
}
